import ApiClient from '@/api/apiClient';

import type { RequestBody } from 'alova';
import { type DeviceItem } from './deviceManagerApi';

/**
 * BizRuleInstanceInfo对象，规则实例详情表
 */

export interface BizRuleInstanceInfo {
  /**
   * 创建人
   */
  createBy?: string;
  deviceList?: DeviceItem[];
  devices?: DeviceItem[];
  /**
   * 规则id
   */
  ruleId?: string;
  /**
   * 创建人id
   */
  createId?: number;
  /**
   * 创建时间
   */
  createTime?: string;
  /**
   * 主键
   */
  id?: number;
  /**
   * 是否逻辑删除，0否,其他是
   */
  isDelete?: number;
  /**
   * 规则实例描述
   */
  remark?: string;
  /**
   * 规则实例名称
   */
  ruleInstanceName?: string;
  /**
   * 状态0:禁用 1:启用
   */
  status?: number;
  /**
   * 修改人
   */
  updateBy?: string;
  /**
   * 修改人id
   */
  updateId?: number;
  /**
   * 更新时间
   */
  updateTime?: string;
  /**
   * 乐观锁版本号
   */
  version?: number;
  [property: string]: any;
}

/** 规则实例列表 */
export const rulesInstanceListApi = (data: RequestBody) => {
  return ApiClient.Post<API.ListType<BizRuleInstanceInfo>>(
    '/manager/alarm/ruleInstance/page',
    data,
    {
      meta: { auth: true },
    }
  );
};
/** 删除规则实例*/
export const rulesInstanceDeleteApi = (data: Merge<RequestBody, { id: string }>) => {
  return ApiClient.Post(`/manager/alarm/ruleInstance/remove/${data.id}`, data, {
    meta: { auth: true },
  });
};

/** 保存更新规则实例*/
export const rulesInstanceAddOrSaveApi = (data: RequestBody) => {
  return ApiClient.Post(`/manager/alarm/ruleInstance/saveOrUpdate`, data, {
    meta: { auth: true },
  });
};

/** 获取规则实例详情 */
export const rulesInstanceDetailApi = (data: { id: number }) => {
  return ApiClient.Get<BizRuleInstanceInfo>(`/manager/alarm/ruleInstance/get/${data.id}`, {
    meta: { auth: true },
  });
};

/** 获取规则实例详情 */
export const rulesInstanceDetailAllApi = (data: { id: number }) => {
  return ApiClient.Get<BizRuleInstanceInfo>(`/manager/alarm/ruleInstance/getDetail/${data.id}`, {
    meta: { auth: true },
  });
};

/** 获取规则实例详情 */
export const rulesInstanceStatusApi = (data: { ruleInstanceId: number; status: number }) => {
  return ApiClient.Get<BizRuleInstanceInfo>(
    `/manager/alarm/ruleInstance/status/${data.ruleInstanceId}/${data.status}`,
    {
      meta: { auth: true },
    }
  );
};
